package com.xwy.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwy.entity.SysUser;
import com.xwy.service.UserService;
import com.xwy.util.TokenContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Controller
public class SysUserController {
    @Resource
    private UserService userService;


    /**
     * 完善用户信息
     */
    @RequestMapping(value = "/user/update-message", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject updateUser(@RequestBody SysUser sysUser) {
        JSONObject json = new JSONObject();
        sysUser.setUno(TokenContext.getUno());
        System.out.println(sysUser.toString());
        boolean result = userService.updateSysUser(sysUser);
        if (result) {
            json.put("status", 0);
            json.put("message", "修改成功");
        } else {
            json.put("status", 1);
            json.put("message", "修改失败");
        }
        return json;
    }

    /**
     * 查看个人信息
     */
    @RequestMapping(value = "/user/userInfo", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject findUser() {
        JSONObject json = new JSONObject();
        String uno = TokenContext.getUno();
        SysUser user = userService.findSysUserByUno(uno);
        System.out.println(user);
        if (user != null) {
            json.put("status", 0);
            json.put("message", "查询成功");
            json.put("data", user);
        } else {
            json.put("status", 1);
            json.put("message", "查询失败");
        }
        return json;
    }


}

